home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 8 code / TValidText / UDateTimeText.p < prev    next >
Encoding:
Text File  |  1991-10-09  |  8.1 KB  |  287 lines  |  [TEXT/MPS ]

  1. {**********************************************************************************
  2. UDateTimeText.p
  3.     Classes implementing the ability to enter dates and times as text in
  4.     dialogs.
  5. **********************************************************************************}
  6.  
  7. UNIT UDateTimeText;
  8.  
  9. INTERFACE
  10. USES
  11.     { • MacApp }
  12.     UMacApp,
  13.     UMacAppUtilities,
  14.     
  15.     { • building blocks }
  16.     UTEView,
  17.     UDialog,
  18.     
  19.     { • Implementation use }
  20.     ToolUtils,
  21.     Packages,
  22.     Script,
  23.     
  24.     { • Application Units }
  25.     UDateTimeUtilities,
  26.     UValidText;
  27.  
  28. CONST
  29.     { The toolbox type DateForm is defined (IM v1 p504) as follows:
  30.             DateForm = (shortDate, longDate, abbrevDate);
  31.         These routines use the ordinal values (0, 1, 2) of these forms, plus
  32.         the new form defDateForm ("Default Date Form", 255), which means "use
  33.         the current global date form." }
  34.     kDefDateForm        =   255;        { use the global date form value }
  35.     
  36.     kInvalidDateReasons    =     701;        { resID of the STR# resource containing
  37.                                             reasons why date text wouldn't validate. }
  38.     
  39.     kInvalidTimeReasons    =     702;        { resID of the STR# resource containing
  40.                                             reasons why time text wouldn't validate. }
  41.  
  42.  
  43.     
  44.     {###############################################################################
  45.     Global Routines
  46.     ###############################################################################}
  47.     
  48.     PROCEDURE InitUDateTimeText(
  49.                             theDateForm:    DateForm);
  50.                         
  51.     PROCEDURE SetDefaultDateForm(
  52.                             theDateForm:    DateForm);
  53.                             
  54.     FUNCTION  GetDefaultDateForm
  55.                             :DateForm;
  56.     
  57.  
  58. TYPE
  59.     {###############################################################################
  60.     TDateEditText
  61.         A TDateEditText view is one which is expected to contain a valid date
  62.         string.  This expectation is enforced by the Validate() method.
  63.     ###############################################################################}
  64.     
  65.     DateTextTemplatePtr    = ^DateTextTemplate;
  66.     DateTextTemplate    = RECORD
  67.         theDateForm:            INTEGER;
  68.     END;  { DateTextTemplate }
  69.                                                 
  70.     TDateEditText = OBJECT(TValidText)
  71.         fDateForm:                INTEGER;
  72.         fDateSecs:                LongDateTime;
  73.         
  74.         PROCEDURE TDateEditText.IDateEditText(
  75.                                 itsSuperView:    TView;
  76.                                 itsLocation:    VPoint;
  77.                                 itsSize:        VPoint;
  78.                                 strict:            BOOLEAN;
  79.                                 required:        BOOLEAN;
  80.                                 itsDateForm:    INTEGER;
  81.                                 itsDateSecs:    LongDateTime);
  82.         
  83.         PROCEDURE TDateEditText.IRes(
  84.                                 itsDocument:    TDocument;
  85.                                 itsSuperView:    TView;
  86.                             VAR itsParams:        Ptr);
  87.                                 OVERRIDE;
  88.  
  89.         PROCEDURE TDateEditText.WRes(
  90.                                 theResource:    ViewRsrcHndl;
  91.                             VAR    itsParams:        Ptr);
  92.                                 OVERRIDE;
  93.  
  94.         PROCEDURE TDateEditText.WriteRes(
  95.                                 theResource:    ViewRsrcHndl;
  96.                             VAR itsParams:        Ptr);
  97.                                 OVERRIDE;
  98.         
  99.         PROCEDURE TDateEditText.SetDateSecs(
  100.                                 dateSecs:        LongDateTime;
  101.                                 redraw:            BOOLEAN);
  102.             { Set the date displayed by the item to the given date.  Update the
  103.                 item's text to reflect the change. }
  104.         
  105.         PROCEDURE TDateEditText.SetDateForm(
  106.                                 theDateForm:    INTEGER;
  107.                                 redraw:            BOOLEAN);
  108.             { Set the date form to the given value.  Update the current text
  109.                 to reflect the change. }
  110.         
  111.         FUNCTION  TDateEditText.GetDateSecs
  112.                                 :LongDateTime;
  113.         
  114.         FUNCTION  TDateEditText.GetDateForm
  115.                                 :INTEGER;
  116.             { Returns the value of fDateForm (which may be kDefDateForm). }
  117.         
  118.         FUNCTION  TDateEditText.CurrentDateForm
  119.                                 :DateForm;
  120.             { Returns the DateForm with which the text in this item will be drawn.
  121.                 If fDateForm is in [0..2], then the value of fDateForm will be
  122.                 returned.  If fDateForm = kDefDateForm, then the value of the
  123.                 global variable gDefaultDateForm will be returned. }
  124.         
  125.         PROCEDURE TDateEditText.UpdateText(
  126.                                 redraw:            BOOLEAN);
  127.                                 OVERRIDE;
  128.             { This routine replaces the text in the object with text that reflects
  129.                 the object's fDateSecs and fDateForm values. }
  130.  
  131.         FUNCTION  TDateEditText.IsValid(
  132.                             VAR    theText:        Str255;
  133.                             VAR    whyNot:            INTEGER)
  134.                                 :BOOLEAN;
  135.                                 OVERRIDE;
  136.             { If the text is valid, then this function returns TRUE, and whyNot
  137.                 is set to the value noErr (0).  If the text is invalid, then the
  138.                 function returns FALSE and whyNot is set to a value indicating
  139.                 the reason why the text is invalid. }
  140.  
  141.         FUNCTION  TDateEditText.HandleValidText(
  142.                             VAR    theText:        Str255)
  143.                                 :LONGINT;
  144.                                 OVERRIDE;
  145.             { This routine updates SELF's internal instance variables to reflect
  146.                 the valid text. }
  147.  
  148.         PROCEDURE TDateEditText.ErrorToString(
  149.                                 theError:        INTEGER;
  150.                             VAR    theString:        Str255);
  151.                                 OVERRIDE;
  152.             { This routine sets theString to the string which best explains
  153.                 the given error.  It is intended to be called only from
  154.                 ValidationErrorAlert(). }
  155.  
  156.         PROCEDURE TDateEditText.PrepareErrorAlert(
  157.                             VAR    theText:        Str255;
  158.                                 theError:        INTEGER);
  159.                                 OVERRIDE;
  160.             { The routine sets up the dialog that is displayed by
  161.                 ValidationErrorAlert(). }
  162.                                 
  163.         {$IFC qInspector}
  164.         PROCEDURE TDateEditText.Fields(
  165.                                 PROCEDURE DoToField(
  166.                                     fieldName:        Str255;
  167.                                     fieldAddr:        Ptr;
  168.                                     fieldType:        INTEGER));
  169.                                 OVERRIDE;
  170.         {$ENDC qInspector}
  171.     END;  { TDateEditText }
  172.     
  173.     
  174.     
  175.     
  176.     
  177.     
  178.     
  179.     {###############################################################################
  180.     TTimeEditText
  181.         A TTimeEditText view is one which is expected to contain a valid time
  182.         string.  This expectation is enforced by the Validate() method.
  183.     ###############################################################################}
  184.     
  185.     TimeTextTemplatePtr    = ^TimeTextTemplate;
  186.     TimeTextTemplate    = RECORD
  187.         wantSeconds:            BOOLEAN;
  188.         reserved:                BOOLEAN;
  189.     END;  { TimeTextTemplate }
  190.     
  191.     TTimeEditText = OBJECT(TValidText)
  192.         fTimeSecs:                LONGINT;
  193.         fWantSeconds:            BOOLEAN;
  194.  
  195.         PROCEDURE TTimeEditText.ITimeEditText(
  196.                                 itsSuperView:    TView;
  197.                                 itsLocation:    VPoint;
  198.                                 itsSize:        VPoint;
  199.                                 strict:            BOOLEAN;
  200.                                 required:        BOOLEAN;
  201.                                 wantSeconds:    BOOLEAN;
  202.                                 itsTimeSecs:    LONGINT);
  203.         
  204.         PROCEDURE TTimeEditText.IRes(
  205.                                 itsDocument:    TDocument;
  206.                                 itsSuperView:    TView;
  207.                             VAR itsParams:        Ptr);
  208.                                 OVERRIDE;
  209.  
  210.         PROCEDURE TTimeEditText.WRes(
  211.                                 theResource:    ViewRsrcHndl;
  212.                             VAR    itsParams:        Ptr);
  213.                                 OVERRIDE;
  214.  
  215.         PROCEDURE TTimeEditText.WriteRes(
  216.                                 theResource:    ViewRsrcHndl;
  217.                             VAR itsParams:        Ptr);
  218.                                 OVERRIDE;
  219.         
  220.         PROCEDURE TTimeEditText.SetTimeSecs(
  221.                                 timeSecs:        LONGINT;
  222.                                 redraw:            BOOLEAN);
  223.         
  224.         PROCEDURE TTimeEditText.SetWantSeconds(
  225.                                 wantSeconds:    BOOLEAN;
  226.                                 redraw:            BOOLEAN);
  227.         
  228.         FUNCTION  TTimeEditText.GetTimeSecs
  229.                                 :LONGINT;
  230.         
  231.         FUNCTION  TTimeEditText.GetWantSeconds
  232.                                 :BOOLEAN;
  233.         
  234.         PROCEDURE TTimeEditText.UpdateText(
  235.                                 redraw:            BOOLEAN);
  236.                                 OVERRIDE;
  237.             { This routine replaces the text in the object with text that
  238.                 reflects the object's fTimeSecs and fWantSeconds values. }
  239.  
  240.         FUNCTION  TTimeEditText.IsValid(
  241.                             VAR    theText:        Str255;
  242.                             VAR    whyNot:            INTEGER)
  243.                                 :BOOLEAN;
  244.                                 OVERRIDE;
  245.             { If the text is valid, then this function returns TRUE, and whyNot
  246.                 is set to the value noErr (0).  If the text is invalid, then the
  247.                 function returns FALSE and whyNot is set to a value indicating
  248.                 the reason why the text is invalid. }
  249.  
  250.         FUNCTION  TTimeEditText.HandleValidText(
  251.                             VAR    theText:        Str255)
  252.                                 :LONGINT;
  253.                                 OVERRIDE;
  254.             { This routine updates SELF's internal instance variables to reflect
  255.                 the valid text. }
  256.  
  257.         PROCEDURE TTimeEditText.ErrorToString(
  258.                                 theError:        INTEGER;
  259.                             VAR    theString:        Str255);
  260.                                 OVERRIDE;
  261.             { This routine sets theString to the string which best explains
  262.                 the given error.  It is intended to be called only from
  263.                 ValidationErrorAlert(). }
  264.  
  265.         PROCEDURE TTimeEditText.PrepareErrorAlert(
  266.                             VAR    theText:        Str255;
  267.                                 theError:        INTEGER);
  268.                                 OVERRIDE;
  269.             { The routine sets up the dialog that is displayed by
  270.                 ValidationErrorAlert(). }
  271.                                 
  272.         { debugger stuff }
  273.         {$IFC qInspector}
  274.         PROCEDURE TTimeEditText.Fields(
  275.                                 PROCEDURE DoToField(
  276.                                     fieldName:        Str255;
  277.                                     fieldAddr:        Ptr;
  278.                                     fieldType:        INTEGER));
  279.                                 OVERRIDE;
  280.         {$ENDC qInspector}
  281.     END;  { TTimeEditText }
  282.  
  283. IMPLEMENTATION
  284.  
  285. {$I UDateTimeText.inc1.p}
  286.  
  287. END.  { UDateTimeText.p }